package 力扣日常刷题.木23一月.第15天315;

import java.util.Stack;

/**
 * @author 帅小伙
 * @date 2022/3/15
 * @description
 */
public class Demo73有效的括号 {


    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            if(stack.isEmpty()) {
                stack.push(s.charAt(i));
                continue;
            }
            char c = stack.peek();
            char cur = s.charAt(i);
            if(c == '(' && cur == ')'
            || c == '{' && cur == '}'
            || c== '[' && cur == ']'){
                stack.pop();
            }else{
                stack.push(cur);
            }
        }
        return stack.isEmpty();
    }

}
